home *** CD-ROM | disk | FTP | other *** search
- /* printf.c
- This is the printf dcmd. This is mostly to show how dcmds can use the standard
- C library.
-
- Copyright © 1989 Apple Computer, Inc. All rights reserved.
-
- Modification history:
- 16Feb89 sad written
-
- The following MPW commands will build the dcmd and copy it to the
- "Debugger Prefs" file in the System folder. The dcmd's name in
- MacsBug will be the name of the file built by the Linker.
- You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
- C Samples folder into this folder.
-
- C Put.c
- C Printf.c
- Link dcmdGlue.a.o Printf.c.o put.c.o -d DRuntime.o "{Libraries}"Interface.o ∂
- "{CLibraries}StdCLib.o" "{CLibraries}CInterface.o" -sg Main=STDIO -o Printf
- BuildDcmd Printf 1004
- Echo 'include "Printf";' | Rez -a -o "{systemFolder}Debugger Prefs"
- */
-
- #include <stdio.h>
- #include <string.h>
-
- #include <Types.h>
-
- #include "dcmd.h"
- #include "put.h"
-
- pascal void CommandEntry(dcmdBlock* paramPtr)
- {
- switch (paramPtr->request)
- {
- case dcmdInit:
- break;
-
- case dcmdHelp:
- dcmdDrawLine("\pprintf \"format\" arg...");
- dcmdDrawLine("\p Displays the arguments according to the format (no floating point).");
- break;
-
- case dcmdDoIt:
- {
- Str255 formatstring;
- unsigned char* formatp = formatstring;
- Str255 formattedstring;
-
- dcmdSwapWorlds(); // not really necessary because we don’t access machine state
-
- (void)dcmdGetNextParameter(formatstring);
-
- p2cstr(formatstring);
-
- while (*formatp != '\0')
- {
- char aformatspec[256];
- size_t speclength;
- long arg;
- Boolean ok;
-
- // find the next format spec (i.e. %d) and print out anything before it
- char* nextp = strchr(formatp, '%');
- if (nextp == nil) nextp = formatp + strlen(formatp);
-
- PutBytesTo(formatp, nextp - formatp, 0);
- formatp = nextp;
-
- // find the length of the format spec
- speclength = strcspn(formatp + 1, "diouxXcspP%") + 2; // we don’t do "feEgGn"
- memcpy(aformatspec, formatp, speclength);
- aformatspec[speclength] = '\0';
- (void)dcmdGetNextExpression(&arg, &ok);
- if (!ok) break;
-
- sprintf(formattedstring, aformatspec, arg);
- PutCStr(formattedstring);
- formatp = formatp + speclength;
- }
- PutLine();
-
- dcmdSwapWorlds();
- }
- break;
-
- default:
- PutPStr("\punknown request ");
- PutUDec(paramPtr->request);
- PutLine();
- break;
- }
- } // CommandEntry
-
- /*
- the following are stubs to override the C library routines so that the dcmd isn’t
- so big.
- */
-
- size_t fwrite (const void *, size_t, size_t, FILE *) { return 0; } // wont’t actually be called by sprintf
- _flsbuf() {} // wont’t actually be called by sprintf
-
- fcvt() {} // used only for floating point %f, etc.
- ecvt() {} // used only for floating point %e, etc.
-